import 'package:flutter/material.dart';

class LoadingContainer extends StatefulWidget {
  final Widget child;
  final bool isLoading;
  final bool cover;

  const LoadingContainer(
      {Key key, this.isLoading, this.cover = false, this.child})
      : super(key: key);

  @override
  _LoadingContainerState createState() => _LoadingContainerState();
}

class _LoadingContainerState extends State<LoadingContainer> {
  @override
  Widget build(BuildContext context) {
    if (!widget.cover) {
      if (widget.isLoading) {
        return _loadingView;
      } else {
        return widget.child;
      }
    }

    return Stack(
      children: [
        widget.child,
        widget.isLoading ? _loadingView : null,
      ],
    );
  }

  Widget get _loadingView {
    return Center(
      child: CircularProgressIndicator(),
    );
  }
}
